package com.sincon.web.controller.bilibili;

import com.alibaba.fastjson2.JSONObject;
import com.sincon.system.domain.QRCodeResponse;
import com.sincon.system.service.impl.BilibiliService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/bilibili")
public class BilibiliController {

    @Autowired
    private BilibiliService bilibiliService;

    /**
     * 获取bilibili登录二维码
     * @return
     */
    @GetMapping("/login/qrcode")
    public ResponseEntity<QRCodeResponse> getLoginQRCode() {
        return ResponseEntity.ok(bilibiliService.getLoginQRCode());
    }

    /**
     * 检测指定qrKey二维码是否扫码登录成功,如果成功则返回token等信息,模拟账密登录流程
     * @param qrcodeKey
     * @return
     */
    @GetMapping("/login/check")
    public ResponseEntity<JSONObject> checkLoginStatus(@RequestParam("qrcode_key") String qrcodeKey) {
        return ResponseEntity.ok(bilibiliService.checkLoginStatus(qrcodeKey));
    }

    /**
     * 获取用户信息
     * @param cookie
     * @return
     */
    @GetMapping("/user/info")
    public JSONObject getUserInfo(@RequestParam String cookie) {
        return bilibiliService.getUserInfo(cookie);
    }

    @GetMapping("/liked-videos")
    public ResponseEntity<JSONObject> getLikedVideos(
        @RequestParam String cookie,
        @RequestParam(defaultValue = "1") int page,
        @RequestParam(defaultValue = "20") int pageSize
    ) {
        return ResponseEntity.ok(bilibiliService.getLikedVideos(cookie, page, pageSize));
    }
} 